package com.milk.controller.admin;

import com.milk.entity.Lottery;
import com.milk.result.Result;
import com.milk.service.LotteryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController("AdminLotteryController")
@RequestMapping("/admin/lottery")
@CrossOrigin
public class LotteryController {
    @Autowired
    private LotteryService lotteryService;

    /**
     * 查询所有抽奖信息
     * @return
     */
    @GetMapping
    public Result<List<Lottery>> selectAll(){
        List<Lottery> list = lotteryService.selectAdminAll();
        return Result.success(list);
    }

    /**
     * 更新抽奖信息
     * @param lottery
     * @return
     */
    @PostMapping("/update")
    public Result update(@RequestBody Lottery lottery){
        System.out.println(lottery);
        lotteryService.updateLottery(lottery);
        return Result.success();
    }

    /**
     * 新增抽奖信息
     * @param lottery
     * @return
     */
    @PostMapping("/insert")
    public Result insert(@RequestBody Lottery lottery){
        lotteryService.insert(lottery);
        return Result.success();
    }

    /**
     * 删除抽奖信息
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    public Result deleteById(@PathVariable Long id){
        lotteryService.deleteById(id);
        return Result.success();
    }

}
